package com.pureut.scheduling.util;

import com.ibm.icu.text.SimpleDateFormat;
import com.pureut.scheduling.domain.vo.HolidayVo;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @Description 周末日期封装
 * @Param
 * @Date
 * @Author hl
 **/
public class WeekendUtils {

    /**
     * 获取当月的所有周末
     * @param year
     * @param month
     * @return
     */
    public static List<HolidayVo> getWeekendInMonth(int year, int month) {
        List<HolidayVo> dateList = new ArrayList<HolidayVo>();
        SimpleDateFormat simdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);// 不设置的话默认为当年
        calendar.set(Calendar.MONTH, month - 1);// 设置月份
        calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为当月第一天
        int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);// 当月最大天数
        for (int i = 0; i < daySize; i++) {
            HolidayVo holidayVo = new HolidayVo();
            int week = calendar.get(Calendar.DAY_OF_WEEK);
            if (week == Calendar.SATURDAY) {// 1代表周日，7代表周六 判断这是一个星期的第几天从而判断是否是周末
               // dateList.add(simdf.format(calendar.getTime()));
                holidayVo.setData(simdf.format(calendar.getTime()));
                holidayVo.setStatus("4");
                holidayVo.setMsg("周六");
                dateList.add(holidayVo);
            }
            if (week == Calendar.SUNDAY) {// 1代表周日，7代表周六 判断这是一个星期的第几天从而判断是否是周末
                //dateList.add(simdf.format(calendar.getTime()));
                holidayVo.setData(simdf.format(calendar.getTime()));
                holidayVo.setStatus("4");
                holidayVo.setMsg("周天");
                dateList.add(holidayVo);
            }
            calendar.add(Calendar.DATE, 1);//在第一天的基础上加1
        }
        return dateList;

    }

    /**
     * 获取当月的所有周六
     * @param year
     * @param month
     * @return
     */
    public static List<HolidayVo> getWeekendInMonthSaturday(int year, int month) {
        List<HolidayVo> dateList = new ArrayList<HolidayVo>();
        SimpleDateFormat simdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);// 不设置的话默认为当年
        calendar.set(Calendar.MONTH, month - 1);// 设置月份
        calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为当月第一天
        int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);// 当月最大天数
        for (int i = 0; i < daySize; i++) {
            HolidayVo holidayVo = new HolidayVo();
            int week = calendar.get(Calendar.DAY_OF_WEEK);
            if (week == Calendar.SATURDAY) {// 1代表周日，7代表周六 判断这是一个星期的第几天从而判断是否是周末
                holidayVo.setData(simdf.format(calendar.getTime()));
                holidayVo.setStatus("4");
                holidayVo.setMsg("休息");
                dateList.add(holidayVo);
            }
            calendar.add(Calendar.DATE, 1);//在第一天的基础上加1
        }
        return dateList;
    }

    /**
     * 获取当月的所有周日
     * @param year
     * @param month
     * @return
     */
    public static List<HolidayVo> getWeekendInMonthSunday(int year, int month) {
        List<HolidayVo> dateList = new ArrayList<HolidayVo>();
        SimpleDateFormat simdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);// 不设置的话默认为当年
        calendar.set(Calendar.MONTH, month - 1);// 设置月份
        calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为当月第一天
        int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);// 当月最大天数
        for (int i = 0; i < daySize; i++) {
            HolidayVo holidayVo = new HolidayVo();
            int week = calendar.get(Calendar.DAY_OF_WEEK);
            if (week == Calendar.SUNDAY) {// 1代表周日，7代表周六 判断这是一个星期的第几天从而判断是否是周末
                holidayVo.setData(simdf.format(calendar.getTime()));
                holidayVo.setStatus("4");
                holidayVo.setMsg("休息");
                dateList.add(holidayVo);
            }
            calendar.add(Calendar.DATE, 1);//在第一天的基础上加1
        }
        return dateList;

    }

}
